package org.budo.support.jedis.util;

import org.budo.support.slf4j.Slf4j;
import org.slf4j.Logger;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @author li
 * @version 1 (2015年3月27日 下午3:39:46)
 * @since Java7
 */
public class JedisPoolUtil {
    private static final Logger log = Slf4j.getLogger();

    public static void close(JedisPool jedisPool) {
        if (null != jedisPool) {
            jedisPool.close();
        }
    }

    /**
     * @param jedisPool
     * @param jedis
     */
    @SuppressWarnings("deprecation")
    public static void returnResource(JedisPool jedisPool, Jedis jedis) {
        if (null == jedisPool || null == jedis) {
            log.error("returnResource error, jedisPool=" + jedisPool + ", jedis=" + jedis);
        } else {
            jedisPool.returnResource(jedis);
        }
    }

    @SuppressWarnings("deprecation")
    public static void returnBrokenResource(JedisPool jedisPool, Jedis jedis) {
        if (null == jedisPool || null == jedis) {
            log.error("returnBrokenResource error, jedisPool=" + jedisPool + ", jedis=" + jedis);
        } else {
            jedisPool.returnBrokenResource(jedis);
        }
    }
}